import 'dart:math' as math;
import 'package:flutter/material.dart';
class RotatingCircle extends StatefulWidget {
  final double radius;
  const RotatingCircle(
      {required this.radius}
      );
  @override
  _RotatingCircleState createState() => _RotatingCircleState();
}

class _RotatingCircleState extends State<RotatingCircle> with SingleTickerProviderStateMixin {
  late AnimationController _controller;

  @override
  void initState() {
    super.initState();
    _controller = AnimationController(
      duration: const Duration(seconds: 2),
      vsync: this,
    )..repeat(); // 自动重复动画
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return AnimatedBuilder(
      animation: _controller,
      builder: (context, child) {
        return Transform.rotate(
          angle: _controller.value * 2 * math.pi, // 将控制器值转换为弧度
          child: CustomPaint(
            size: Size(widget.radius * 2, widget.radius * 2), // 设置画布大小，以适应外圆环直径54*2
            painter: CirclePainter(radius1: widget.radius),
          ),
        );
      },
    );
  }
}

class CirclePainter extends CustomPainter {
  final double radius1;
  const CirclePainter(
      {required this.radius1}
      );
  @override
  void paint(Canvas canvas, Size size) {
    double outerStrokeWidth = 2.0;
    double innerStrokeWidth = 6.0;
    final outerCircleRadius = radius1 - outerStrokeWidth / 2;
    final innerCircleRadius = radius1 - outerStrokeWidth / 2 - innerStrokeWidth / 2;
    final center = Offset(size.width / 2, size.height / 2);

    // 绘制外部完整的细圆环
    final outerCirclePaint = Paint()
      ..color = Color(0xFF0BA3FF)
      ..style = PaintingStyle.stroke
      ..strokeWidth =outerStrokeWidth;

    canvas.drawCircle(center, outerCircleRadius, outerCirclePaint);

    // 绘制内部的3/4粗圆环
    final innerCirclePaint = Paint()
      ..color = Color(0xFF0BA3FF)
      ..style = PaintingStyle.stroke
      ..strokeWidth = innerStrokeWidth
      ..strokeCap = StrokeCap.round; // 圆角结束

    // 开始角度和扫过的弧度（3/4圆）
    final startAngle = -math.pi / 2; // 从顶部开始
    final sweepAngle = 3 / 4 * 2 * math.pi;

    canvas.drawArc(
      Rect.fromCircle(center: center, radius: innerCircleRadius),
      startAngle,
      sweepAngle,
      false,
      innerCirclePaint,
    );
  }

  @override
  bool shouldRepaint(CustomPainter oldDelegate) => true;
}